<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <%
        pageContext.setAttribute("APP_PATH", request.getContextPath());
    %>
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <title>教师</title>
</head>

<jsp:include page="teacher_header.jsp"/>

<div class="container">
    <form class="form-horizontal" id="add" method="post">
        <table class="table table-bordered">
            <div class="form-group">
                <tr>
                    <th>
                        <div class="col-sm-6">项目名称：</div>
                    </th>
                    <th>
                        <input type="hidden" name="teacherid" value="${id_infor}">
                        <input class="form-control" name="projectname">
                    </th>
                </tr>
                <tr>
                    <th>
                        <div class="col-sm-6">项目等级：</div>
                    </th>
                    <th>
                        <input class="form-control" placeholder="校级项目/横向项目/纵向项目" name="projectrank">
                    </th>
                </tr>
                <tr>
                    <th>
                        <div class="col-sm-6">第一负责人：</div>
                    </th>
                    <th>
                        <input class="form-control" name="firstname">
                    </th>
                </tr>
                <tr>
                    <th>
                        <div class="col-sm-6">项目成员：</div>
                    </th>
                    <th>
                        <input class="form-control" name="allname">
                    </th>
                </tr>
                <tr>
                    <th>
                        <div class="col-sm-6">立项日期：</div>
                    </th>
                    <th>
                        <input class="form-control" placeholder="格式：xxxx-xx-xx" id="begintime" name="begintime">
                    </th>
                </tr>
                <tr>
                    <th>
                        <div class="col-sm-6">结束日期：</div>
                    </th>
                    <th>
                        <input class="form-control" placeholder="格式：xxxx-xx-xx" id="endtime" name="endtime">
                    </th>
                </tr>
                <tr>
                    <th>
                        <div class="col-sm-6">项目经费：</div>
                    </th>
                    <th>
                        <input class="form-control" name="projectfunds" value="单位：万（只填数字即可）">
                    </th>
                </tr>
            </div>
        </table>
        <div class="col-md-4 col-md-offset-4">
            <button class="btn btn-primary btn-lg" type="reset">重置</button>
            <button class="btn btn-success btn-lg" id="btn_add_project">提交</button>
        </div>
    </form>
</div>
<script>
    $("#btn_add_project").click(function () {
        var time1 = document.getElementById("begintime").value.trim();
        var time2 = document.getElementById("endtime").value.trim();

        var reg = /^\d{4}-\d{1,2}-\d{1,2}/;

        var regYearMatch1 = reg.test(time1);
        var regYearMatch2 = reg.test(time2);

        if (regYearMatch1 == false || regYearMatch2 == false) {
            alert("日期格式不对");
            return false;
        } else {
            var date1 = parseInt(time1.replace(/\-/g, ""));
            var date2 = parseInt(time2.replace(/\-/g, ""));
            if (date1 > date2) {
                alert("立项日期不得晚于结束日期！请重新填写。");
                return false;
            }

            $.ajax({
                url: "${APP_PATH}/add_project",
                type: "POST",
                dataType:"JSON",
                data: $("#add").serialize(),
                success: function (result) {
                    alert(result.message)
                },
                error: function () {
                    alert("请求失败！");
                    return false;
                }
            });
        }
    });
</script>
</body>
</html>
